$(function(){
    // loginForm登录验证
    $("#loginForm").validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            },
            code: {
                required: true
            }
        },
        messages: {
            username: {
                required: "请输入用户名"
            },
            password: {
                required: "请输入密码"
            },
            code: {
                required: "请输入验证码"
            },
        }
    });

    // 手机号码验证
    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "");

    // 找回密码验证
    $("#findForm").validate({
        rules: {
            username2: {
                required: true,
            },
            phone2: {
                required: true,
                isMobile : true,
                success: function(){

                        if($("#phone2").hasClass("valid")){
                            $("#findSend").attr("disabled",false).removeClass("gray");
                        }else{
                            $("#findSend").attr("disabled",true).addClass("gray");
                        }

                }

            },
            code2: {
                required: true
            },
            password1: {
                required: true,
                minlength: 6,
                maxlength: 20,
            },
            password2: {
                required: true,
                equalTo: "#password1"
            }

        },
        messages: {
            username2: {
                required: "请输入用户名"
            },
            phone2: {
                required: "请输入手机号",
                isMobile : "请正确填写您的手机号码",

            },
            code2: {
                required: "请输入验证码"
            },
            password1: {
                required: "请输入新密码",
                minlength: "密码长度不能小于 6 个字符",
            },
            password2: {
                required: "请输入新密码",
                equalTo: "两次密码输入不一致"
            },
        }
    });

    // 注册
    $("#regForm").validate({
        rules: {
            username3: {
                required: true,
                minlength: 4,
                maxlength: 10,
            },
            phone3: {
                required: true,
                isMobile : true,
                success: function(){
                  
                        if($("#phone3").hasClass("valid")){
                            $("#regSend").attr("disabled",false).removeClass("gray");
                        }else{
                            $("#regSend").attr("disabled",true).addClass("gray");
                        }

                }

            },
            wx3: {
                required: true,
            },
            code3: {
                required: true
            },
            password3: {
                required: true,
                minlength: 6,
                maxlength: 20
            },
            password4: {
                required: true,
                equalTo: "#password3"
            }

        },
        messages: {
            username3: {
                required: "请输入用户名"
            },
            phone3: {
                required: "请输入手机号",
                isMobile : "请正确填写您的手机号码",

            },
            code3: {
                required: "请输入验证码"
            },
            wx3: {
                required: "请输入微信号"
            },
            password3: {
                required: "请输入新密码",
                minlength: "密码长度不能小于 6 个字符",
            },
            password4: {
                required: "请输入新密码",
                minlength: "密码长度不能小于 6 个字符",
                equalTo: "两次密码输入不一致"
            },
        }
    });
   
   // 点击"忘记密码"弹窗
   $("#forgetdPwd").click(function(){
	      layer.alert("请联系客服修改密码");
			return
        //$("#findpwdContainer").addClass("on");
        //$(".mask").show();

   });

   $("#forgetdPwd").click(function(){
       // $("#findpwdContainer").addClass("on");
       // $(".mask").show();

   });

   // 注册弹窗
   $("#regUser").click(function(){
        $("#regContainer").addClass("on");
        $(".mask").show();

   });

    // 关闭找回密码弹窗
   $("#findCancel,.findClose").click(function(){
        $("#findpwdContainer").removeClass("on");
        $(".mask").hide();
   })

   // 关闭注册弹窗
   $("#regCancel,.regClose").click(function(){
        $("#regContainer").removeClass("on");
        $(".mask").hide();
   })

});

// 获取验证码
function clickButton(obj){
    var obj = $(obj);
    obj.attr("disabled","disabled").addClass("gray");/*按钮倒计时*/
    var time = 30;
    var set=setInterval(function(){
        obj.val(--time+"(s)");
    }, 1000);/*等待时间*/
    setTimeout(function(){
        obj.attr("disabled",false).val("重新获取").removeClass("gray");/*倒计时*/
        clearInterval(set);
    }, 30000);
}